VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Detail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
'/******************************************************************/
'/*                                                                */
'/*                      TurboCAD for Windows                      */
'/*                   Copyright (c) 1993 - 2001                    */
'/*             International Microcomputer Software, Inc.         */
'/*                            (IMSI)                              */
'/*                      All rights reserved.                      */
'/*                                                                */
'/******************************************************************/

'DBAPI constants
Const gkGraphic = 11
Const gkArc = 2
Const gkText = 6
Const gfCosmetic = 128&
                                                                                                                                                                                             
'Useful math constants
Const Pi# = 3.14159265

'Real variant types!
Const typeEmpty = 0
Const typeInteger = 2
Const typeLong = 3
Const typeSingle = 4
Const typeDouble = 5
Const typeCurrency = 6
Const typeDate = 7
Const typeString = 8
Const typeObject = 9
Const typeBoolean = 11
Const typeVariant = 12
Const typeIntegerEnum = typeInteger + 100
Const typeLongEnum = typeLong + 100
Const typeStringEnum = typeString + 100

'Stock property pages
Const ppStockPen = 1
Const ppStockBrush = 2
Const ppStockText = 4
Const ppStockInsert = 8
Const ppStockViewport = 16
Const ppStockAuto = 32

'Property Ids
Const idDiameter = 1
Const idLength = 2
Const idHType = 3
Const idHoleView = 4

Const idLengthOld = 5
Const idLengthThread = 6

Const idDiameterOld = 7
Const idHTypeOld = 8
Const idHoleViewOld = 9
Const idLengthThreadOld = 10

Const idX0Old = 11
Const idY0Old = 12
Const idX1Old = 13
Const idY1Old = 14
Const idX2Old = 15
Const idY2Old = 16


'Property enums
Const NUM_TYPES = 0


'Number of properties, pages, wizards
Const NUM_PROPERTIES = 16
Const NUM_PAGES = 1
Const NUM_WIZARDS = 0

Private PColor As Long
Private BColor As Long

Private Sub Class_Initialize()
    'Initialize class variables
End Sub

'Returns the user-visible description of this RegenMethod
Public Property Get Description() As String
    Description = "Holes"
End Property

'Returns the persistent class id for this RegenMethod's property section
Public Property Get ClassID() As String
    ClassID = "{FDB6F1C3-9631-11d1-A40A-0000B465872B}"
End Property

'Retrieve types and names
Public Function GetPropertyInfo(Names As Variant, Types As Variant, _
    IDs As Variant, Defaults As Variant) As Long
    ReDim Names(NUM_PROPERTIES), Types(NUM_PROPERTIES), _
        IDs(NUM_PROPERTIES), Defaults(NUM_PROPERTIES)
        
    Names(0) = "DiameterH"
    Types(0) = typeDouble
    IDs(0) = idDiameter
    Defaults(0) = 1#

    Names(1) = "LengthH"
    Types(1) = typeDouble
    IDs(1) = idLength
    Defaults(1) = 3#
    
    Names(2) = "HType"
    Types(2) = typeString
    IDs(2) = idHType
    Defaults(2) = "Hole1"
    
    Names(3) = "HoleView"
    Types(3) = typeString
    IDs(3) = idHoleView
    Defaults(3) = "FrontSection"
    
    Names(4) = "LengthOldH"
    Types(4) = typeDouble
    IDs(4) = idLengthOld
    Defaults(4) = 3#
   
    Names(5) = "LengthThreadH"
    Types(5) = typeDouble
    IDs(5) = idLengthThread
    Defaults(5) = 1.5
   
    Names(6) = "DiameterOldH"
    Types(6) = typeDouble
    IDs(6) = idDiameterOld
    Defaults(6) = 1#
    
    Names(7) = "HTypeOld"
    Types(7) = typeString
    IDs(7) = idHTypeOld
    Defaults(7) = "HexBolt"
    
    Names(8) = "HoleViewOld"
    Types(8) = typeString
    IDs(8) = idHoleViewOld
    Defaults(8) = "FrontSection"
    
    Names(9) = "LengthThreadOldH"
    Types(9) = typeDouble
    IDs(9) = idLengthThreadOld
    Defaults(9) = 1.5
    
    Names(10) = "X0OldH"
    Types(10) = typeDouble
    IDs(10) = idX0Old
    Defaults(10) = 0#
   
    Names(11) = "Y0OldH"
    Types(11) = typeDouble
    IDs(11) = idY0Old
    Defaults(11) = 0#
   
    Names(12) = "X1OldH"
    Types(12) = typeDouble
    IDs(12) = idX1Old
    Defaults(12) = 3#
   
    Names(13) = "Y1OldH"
    Types(13) = typeDouble
    IDs(13) = idY1Old
    Defaults(13) = 0#
   
    Names(14) = "X2OldH"
    Types(14) = typeDouble
    IDs(14) = idX2Old
    Defaults(14) = 1.5
   
    Names(15) = "Y2OldH"
    Types(15) = typeDouble
    IDs(15) = idY2Old
    Defaults(15) = 0#
    
   GetPropertyInfo = NUM_PROPERTIES
End Function

'Get the number of property pages supporting this RegenMethod
Public Function GetPageInfo(ByVal AGraphic As Object, StockPages As Long, _
    Names As Variant) As Long
    ReDim Names(NUM_PAGES)

    'Need the form
''    Load frmHole
''    Names(0) = frmHole.Caption
''    Unload frmHole
    Names(0) = LoadResString(101)
    StockPages = ppStockBrush + ppStockPen + ppStockAuto
    GetPageInfo = NUM_PAGES
End Function

Public Function GetWizardInfo(Names As Variant) As Long
    ReDim Names(NUM_WIZARDS)
    GetWizardInfo = NUM_WIZARDS
End Function

'Enumerate the names and values of a specified property
Public Function GetEnumNames(ByVal PropID As Long, Names As Variant, Values As Variant) As Long
        GetEnumNames = 0
End Function

Public Function PageControls(ByVal ThisRegenMethod As Object, ByVal Graphic As Object, ByVal PageNumber As Long, ByVal SaveProperties As Boolean) As Boolean
        'Set up error function
        On Error GoTo Failed
        Dim Diameter#, Length#, LengthThread#
        If SaveProperties Then
            'OK button on property page was clicked
            'Form is still loaded
            With frmHole
                'Need On Error statement for the case where you have
                'RRect Turbo Shape and ahother "shape" selected
                On Error Resume Next
                'When the property page is closed, transfer the numeric
                'Diameter value from the TextBox to the Graphic
                'Get the value as a double-precision number
                Diameter# = CDbl(.txtdd.Text)
                Length# = CDbl(.txtLen.Text)
                LengthThread# = CDbl(.txtThread.Text)
                TypeH = .List1.Text
'                ViewH = .List2.Text
                'Make sure it's between 0 and 100
                If Diameter# < 0# Then Diameter# = 1#
                If Diameter# > 3# Then Diameter# = 3#
                If LengthThread > Length Then LengthThread = Length
                'Set the roundness property value in the Graphic
                Graphic.Properties("DiameterH") = Diameter#
                Graphic.Properties("LengthH") = Length#
                Graphic.Properties("LengthThreadH") = LengthThread#
                Graphic.Properties("HType") = TypeH
            End With
        Else
            'Property page is about to be opened
            'Make sure the form is loaded
                Diameter# = Graphic.Properties("DiameterH")
                Length# = Graphic.Properties("LengthH")
                LengthThread = Graphic.Properties("LengthThreadH")
                TypeH = Graphic.Properties("HType")
            Load frmHole
            With frmHole
            
                'If more than one RRect is selected and they do not
                'have the same properties, don't set up this field
                On Error GoTo NoRType

                'When the property page is opening, transfer the numeric
                'Set the TextBox control's text
                .txtdd.Text = Diameter#
                .txtLen = Length#
                .txtThread.Text = LengthThread#
NoRType:
            End With
        End If

        PageControls = True
        Exit Function

Failed:
        'For debugging purposes, report that an error occurred
        If Err.Number <> 0 Then
            MsgBox "Error in PageControls: " & Err.Description
        End If

        'Return false if an error occurred
        PageControls = False
End Function

Public Function PageDone(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant)
        'Done with form
        Unload frmHole
End Function

Public Function PropertyPages(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant) As Boolean
    With frmHole
        .Show vbModal
        PropertyPages = Not .DialogCanceled
    End With
End Function

Public Function Wizard(ByVal ThisRegenMethod As Object, Optional WizardNumber As Variant) As Boolean
    Wizard = False
End Function

'Called when vertex has been moved, or other geometry change
Public Function OnGeometryChanged(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant)
    'Do nothing
    'Regen Graphic
End Function

'Called when vertex is moved, or other geometry change
Public Function OnGeometryChanging(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant) As Boolean
    'OK to continue with change
    OnGeometryChanging = True
End Function

Public Function OnNewGraphic(ByVal grfThis1 As Object, ByVal boolCopy As Boolean) As Boolean
    If boolCopy Then
        'Vertices are already added for us...
        OnNewGraphic = True
        Exit Function
    End If
Dim grfThis As Graphic
    Set grfThis = grfThis1
    On Error GoTo Failed
    'New Graphic being created
    'X, Y, Z, PenDown, Selectable, Snappable, Editable, Linkable
    'First Vertex is "first point of axis"
    grfThis.Vertices.Add 0#, 0, 0#, False, True, True, True, True, False
    
    'Second Vertex is "Second point of axis"
    grfThis.Vertices.Add 3#, 0, 0#, False, True, True, True, True, False
    
    'Third Vertex is "Point on theard"
    grfThis.Vertices.Add 1.5, 0, 0#, False, True, True, True, True, False
     
    grfThis.Properties("PenColor") = RGB(0, 0, 0)
    grfThis.Properties("BrushColor") = RGB(255, 255, 255)
    OnNewGraphic = True
    Exit Function

Failed:
    'Return false on failure
    OnNewGraphic = False
End Function

'Function called whenever a copy of a graphic is being made
Public Function OnCopyGraphic(ByVal grfCopy As Object, ByVal grfSource As Object) As Boolean
    'Return false on failure
    OnCopyGraphic = True
End Function

'Notification function called after graphic property is saved
Public Function OnPropertyChanged(ByVal Graphic As Object, ByVal PropID As Long, _
        ValueOld As Variant, ValueNew As Variant)
    'Do nothing
End Function

'Notification function called when graphic property is saved
Public Function OnPropertyChanging(ByVal Graphic As Object, ByVal PropID As Long, _
        ValueOld As Variant, ValueNew As Variant) As Boolean
    'OK to proceed
    OnPropertyChanging = True
End Function

'Notification function called when graphic property is retrieved
Public Function OnPropertyGet(ByVal Graphic As Object, ByVal PropID As Long)
    'Do nothing
End Function

'Called when we need to update our object
Public Function Regen(ByVal grfThis1 As Object)
        'Setup error handler
        On Error GoTo Failed
Dim grfThis As Graphic
        Set grfThis = grfThis1
        'Set up lock (prevent recursion)

Dim LockCount&
        LockCount& = grfThis.RegenLock

        PColor = grfThis.Properties("PenColor")
''AALB problem with load old files
' AALB try to fix bug with reading files from TC v6.5 (problem is that some sdk regens
' has Type = 7(Group, must be GRAPHIc (11))
On Error Resume Next
Err.Clear
        BColor = grfThis.Properties("BrushColor")
        If Err.Number <> 0 Then
            BColor = RGB(255, 255, 255)
            Err.Clear
        End If
        'Setup error handler (make sure lock is removed)
        On Error GoTo FailedLock
        If LockCount& = 0 Then
            'Delete any previous cosmetic children
            grfThis.Graphics.Clear gfCosmetic
            
Dim dd#, ddOld#
Dim TypeHOld As String, ViewHOld As String
                dd = grfThis.Properties("DiameterH")
                ddOld = grfThis.Properties("DiameterOldH")
                
                TypeH = grfThis.Properties("HType")
                TypeHOld = grfThis.Properties("HTypeOld")
                
                ViewH = grfThis.Properties("HoleView")
                ViewHOld = grfThis.Properties("HoleViewOld")
Dim x0Old#, y0Old#, x1Old#, y1Old#, x2Old#, y2Old#
                x0Old = grfThis.Properties("x0OldH")
                y0Old = grfThis.Properties("y0OldH")
                x1Old = grfThis.Properties("x1OldH")
                y1Old = grfThis.Properties("y1OldH")
                x2Old = grfThis.Properties("x2OldH")
                y2Old = grfThis.Properties("y2OldH")
                
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dim Salp#, Calp#, L#
Dim X00#, Y00#, X01#, Y01#, X02#, Y02#
Dim LenProp#, LenOld#
        LenProp = grfThis.Properties("LengthH")
        LenOld = grfThis.Properties("LengthOldH")
Dim LenPropThread#, LenThreadOld#
Dim LThread#

        LenPropThread = grfThis.Properties("LengthThreadH")
        LThread = LenPropThread
        LenThreadOld = grfThis.Properties("LengthThreadOldH")

        With grfThis.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            X02 = .Item(2).X
            Y02 = .Item(2).Y
            L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
            If Abs(L) < 0.001 Then
                X00 = x0Old
                Y00 = y0Old
                X01 = x1Old
                Y01 = y1Old
                X02 = x2Old
                Y02 = y2Old
                L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
                .Item(0).X = X00
                .Item(0).Y = Y00
                .Item(1).X = X01
                .Item(1).Y = Y01
                .Item(2).X = X02
                .Item(2).Y = Y02
            End If
            Salp = (Y01 - Y00) / L
            Calp = (X01 - X00) / L
        End With
        
' If there are changes in Property's Page
        If Abs(dd - ddOld) > 0.001 Or Abs(LenProp - LenOld) > 0.001 Or Abs(LenPropThread - LenThreadOld) > 0.001 Or TypeH <> TypeHOld Or ViewH <> ViewHOld Then
            If ViewH = "FrontSection" And (ViewHOld = "Front" Or ViewHOld = "Top") Then
Dim Calp2#, Salp2#
                Calp2 = Calp
                Salp2 = Salp
                Calp = Salp2
                Salp = -Calp2
                X01 = X00 + LenProp * Calp
                Y01 = Y00 + LenProp * Salp
                With grfThis.Vertices
                    .Item(1).X = X01
                    .Item(1).Y = Y01
                    L = LenProp
                End With
                X02 = X00 + (X01 - X00) * LenPropThread / LenProp
                Y02 = Y00 + (Y01 - Y00) * LenPropThread / LenProp
                With grfThis.Vertices
                    .Item(2).X = X02
                    .Item(2).Y = Y02
                End With
            End If
            If Abs(LenProp - LenOld) > 0.001 And ViewH = ViewHOld Then
                X01 = X00 + LenProp * Calp
                Y01 = Y00 + LenProp * Salp
                With grfThis.Vertices
                    .Item(1).X = X01
                    .Item(1).Y = Y01
                    L = LenProp
                End With
            End If
            If Abs(LenPropThread - LenThreadOld) > 0.001 And ViewH = ViewHOld Then
                If LenPropThread > LenProp Then
                    grfThis.Properties("LengthThreadH") = CDbl(Format(LenProp, "###0.00"))
                    LenPropThread = LenProp
                    LThread = LenPropThread
                End If
                X02 = X00 + (X01 - X00) * LenPropThread / LenProp
                Y02 = Y00 + (Y01 - Y00) * LenPropThread / LenProp
                With grfThis.Vertices
                    .Item(2).X = X02
                    .Item(2).Y = Y02
                End With
            End If
            GoTo LL
        End If
        
' If change location of the at least one base vertex
        If Abs(X00 - x0Old) > 0.001 Or Abs(Y00 - y0Old) > 0.001 Or Abs(X01 - x1Old) > 0.001 Or Abs(Y01 - y1Old) > 0.001 Or Abs(X02 - x2Old) > 0.001 Or Abs(Y02 - y2Old) > 0.001 Then
            If ViewH = "Front" Or ViewH = "Top" Then GoTo LL
            If Abs(X00 - x0Old) > 0.001 Or Abs(Y00 - y0Old) > 0.001 Or Abs(X01 - x1Old) > 0.001 Or Abs(Y01 - y1Old) > 0.001 Then
                grfThis.Properties("LengthH") = CDbl(Format(L, "###0.00"))
                If LThread > L Then
                    LThread = L
                    grfThis.Properties("LengthThreadH") = CDbl(Format(LThread, "###0.00"))
                End If
                X02 = X00 + (X01 - X00) * LThread / L
                Y02 = Y00 + (Y01 - Y00) * LThread / L
                With grfThis.Vertices
                    .Item(2).X = X02
                    .Item(2).Y = Y02
                End With
            End If
            If Abs(X00 - x0Old) < 0.001 And Abs(Y00 - y0Old) < 0.001 And Abs(X01 - x1Old) < 0.001 And Abs(Y01 - y1Old) < 0.001 Then
                If Abs(X02 - x2Old) > 0.001 Or Abs(Y02 - y2Old) > 0.001 Then
 Dim Salp1#, Calp1#
                    Salp1 = (Y01 - Y00) / L
                    Calp1 = (X01 - X00) / L
                    LThread = (Y02 - Y00) * Salp1 + (X02 - X00) * Calp1
                    If LThread > L Then LThread = L
                    If LThread < 0 Then LThread = 0#
                    grfThis.Properties("LengthThreadH") = CDbl(Format(LThread, "###0.00"))
                    X02 = X00 + (X01 - X00) * LThread / L
                    Y02 = Y00 + (Y01 - Y00) * LThread / L
                    With grfThis.Vertices
                        .Item(2).X = X02
                        .Item(2).Y = Y02
                    End With
                End If
            End If
        End If
LL:
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            If TypeH = "Hole1" Then Call Hole1(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
            If TypeH = "Hole2" Then Call Hole2(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
            If TypeH = "Hole3" Then Call Hole3(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
            If TypeH = "Hole4" Then Call Hole4(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
            If TypeH = "Hole5" Then Call Hole5(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
            'Add visible child Graphics
        End If
        grfThis.Properties("DiameterOldH") = grfThis.Properties("DiameterH")
        grfThis.Properties("LengthOldH") = grfThis.Properties("LengthH")
        grfThis.Properties("LengthThreadOldH") = grfThis.Properties("LengthThreadH")
        grfThis.Properties("HTypeOld") = TypeH
        grfThis.Properties("HoleViewOld") = ViewH
        grfThis.Properties("x0OldH") = X00
        grfThis.Properties("y0OldH") = Y00
        grfThis.Properties("x1OldH") = X01
        grfThis.Properties("y1OldH") = Y01
        grfThis.Properties("x2OldH") = X02
        grfThis.Properties("y2OldH") = Y02

        
        grfThis.RegenUnlock
        Exit Function

FailedLock:
        'Remove lock
        grfThis.RegenUnlock

Failed:
End Function

Public Function Draw(ByVal grfThis As Object, ByVal view As Object, Optional mat As Variant) As Boolean
    'Return True if we did the redraw (no further processing necessary, no children will be drawn).
    'Since this is just a test, we return False to let TurboCAD do the drawing operation.
    Draw = False
End Function
Private Function Angle(sinb As Double, cosb As Double) As Double

        If Abs(cosb) < 0.0001 Then
            If sinb > 0 Then
                Angle = Pi / 2
            Else
                Angle = 3 * Pi / 2
            End If
        Else
            If sinb >= 0 And cosb > 0 Then Angle = Atn(sinb / cosb)
            If sinb >= 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
            If sinb < 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
            If sinb < 0 And cosb > 0 Then Angle = 2 * Pi + Atn(sinb / cosb)
        End If
End Function

Private Sub Hole1(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)

Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            .Item(2).X = X01
            .Item(2).Y = Y01
            .Item(2).Selectable = False
            .Item(2).Editable = False
        End With
Dim del#
        del = 0.1 * dd
        
Dim X0(8)
Dim Y0(8)
Dim X(8)
Dim Y(8)
        X0(1) = 0#
        Y0(1) = dd / 2# + del
          
        X0(2) = X0(1)
        Y0(2) = -Y0(1)
          
        X0(3) = del
        Y0(3) = dd / 2#
          
        X0(4) = X0(3)
        Y0(4) = -Y0(3)
          
        X0(5) = L - del
        Y0(5) = dd / 2#
          
        X0(6) = X0(5)
        Y0(6) = -Y0(5)
          
        X0(7) = L
        Y0(7) = dd / 2 + del
          
        X0(8) = X0(7)
        Y0(8) = -Y0(7)
          
        
Dim i%
        For i = 1 To 8
             X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
             Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
        Next i
Dim GrChild As Graphic
            'Add child Graphics
' ##########################################################################
' ##########################################################################
        If ScrewView = "FrontSection" Then
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, True, True, False, False, False, False
                .Add X(7), Y(7), 0, True, True, False, False, False, False
                .Add X(8), Y(8), 0, True, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
                .Add X(1), Y(1), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Closed = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("BrushStyle") = "Solid"
            GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, False, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
        
        End If
End Sub



Private Sub Hole2(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)

Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            .Item(2).X = X01
            .Item(2).Y = Y01
            .Item(2).Selectable = False
            .Item(2).Editable = False
        End With
Dim del#
        del = 0.1 * dd
        
Dim X0(6)
Dim Y0(6)
Dim X(6)
Dim Y(6)
       
        X0(1) = 0#
        Y0(1) = dd / 2# + del
          
        X0(2) = X0(1)
        Y0(2) = -Y0(1)
          
        X0(3) = del
        Y0(3) = dd / 2#
          
        X0(4) = X0(3)
        Y0(4) = -Y0(3)
          
        X0(5) = L
        Y0(5) = dd / 2#
          
        X0(6) = X0(5)
        Y0(6) = -Y0(5)
          
        
Dim i%
        For i = 1 To 6
             X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
             Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
        Next i
Dim GrChild As Graphic
            'Add child Graphics
' ##########################################################################
' ##########################################################################
        If ScrewView = "FrontSection" Then
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, True, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
                .Add X(1), Y(1), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Closed = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("BrushStyle") = "Solid"
            GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
        
        End If

End Sub


Private Sub Hole3(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)

Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            .Item(2).Selectable = True
            .Item(2).Editable = True
        End With
Dim del#
        del = 0.1 * dd
        
Dim X0(8)
Dim Y0(8)
Dim X(8)
Dim Y(8)
        X0(1) = 0#
        Y0(1) = dd / 2#
          
        X0(2) = X0(1)
        Y0(2) = -Y0(1)
          
        X0(3) = del
        Y0(3) = dd / 2# - del
          
        X0(4) = X0(3)
        Y0(4) = -Y0(3)
          
        X0(5) = L
        Y0(5) = dd / 2# - del
          
        X0(6) = X0(5)
        Y0(6) = -Y0(5)
          
    '-------------------------------
        If LThread > 0 Then
            If LThread > L Then
                LThread = L
                Gr.Properties("LengthThread") = L
            End If
            X0(7) = LThread
        Else
            X0(7) = 0#
        End If
        Y0(7) = dd / 2#
        
        X0(8) = X0(7)
        Y0(8) = -Y0(7)
   
        
Dim i%
        For i = 1 To 8
             X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
             Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
        Next i
Dim GrChild As Graphic
            'Add child Graphics
' ##########################################################################
' ##########################################################################
        If ScrewView = "FrontSection" Then
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, True, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
                .Add X(1), Y(1), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Closed = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("BrushStyle") = "Solid"
            GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
        'Threading
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(7), Y(7), 0, True, True, False, False, False, False
                .Add X(8), Y(8), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Properties("PenColor") = PColor
        
        End If

End Sub




Private Sub Hole4(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)

Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            .Item(2).Selectable = True
            .Item(2).Editable = True
        End With
Dim del#
        del = 0.1 * dd
        
Dim X0(9)
Dim Y0(9)
Dim X(9)
Dim Y(9)
        X0(1) = 0#
        Y0(1) = dd / 2#
          
        X0(2) = X0(1)
        Y0(2) = -Y0(1)
          
        X0(3) = del
        Y0(3) = dd / 2# - del
          
        X0(4) = X0(3)
        Y0(4) = -Y0(3)
          
        X0(5) = L
        Y0(5) = dd / 2# - del
          
        X0(6) = X0(5)
        Y0(6) = -Y0(5)
          
        X0(7) = L + dd / 2# * Tan(Pi / 6)
        Y0(7) = 0#
    '-------------------------------
        If LThread > 0 Then
            If LThread > L Then
                LThread = L
                Gr.Properties("LengthThread") = L
            End If
            X0(8) = LThread
        Else
            X0(8) = 0#
        End If
        Y0(8) = dd / 2#
        
        X0(9) = X0(8)
        Y0(9) = -Y0(8)
   
        
Dim i%
        For i = 1 To 9
             X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
             Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
        Next i
Dim GrChild As Graphic
            'Add child Graphics
' ##########################################################################
' ##########################################################################
        If ScrewView = "FrontSection" Then
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, True, True, False, False, False, False
                .Add X(7), Y(7), 0, True, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
                .Add X(1), Y(1), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Closed = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("BrushStyle") = "Solid"
            GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, False, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
        'Threading
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(8), Y(8), 0, True, True, False, False, False, False
                .Add X(9), Y(9), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Properties("PenColor") = PColor
        
        End If

End Sub



Private Sub Hole5(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)

Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            .Item(2).Selectable = True
            .Item(2).Editable = True
        End With
Dim del#
        del = 0.1 * dd
        
Dim X0(9)
Dim Y0(9)
Dim X(9)
Dim Y(9)
        X0(1) = 0#
        Y0(1) = dd / 2#
          
        X0(2) = X0(1)
        Y0(2) = -Y0(1)
          
        X0(3) = 0#
        Y0(3) = dd / 2# - del
          
        X0(4) = X0(3)
        Y0(4) = -Y0(3)
          
        X0(5) = L
        Y0(5) = dd / 2# - del
          
        X0(6) = X0(5)
        Y0(6) = -Y0(5)
          
        X0(7) = L + dd / 2# * Tan(Pi / 6)
        Y0(7) = 0#
    '-------------------------------
        If LThread > 0 Then
            If LThread > L Then
                LThread = L
                Gr.Properties("LengthThread") = L
            End If
            X0(8) = LThread
        Else
            X0(8) = 0#
        End If
        Y0(8) = dd / 2#
        
        X0(9) = X0(8)
        Y0(9) = -Y0(8)
   
        
Dim i%
        For i = 1 To 9
             X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
             Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
        Next i
Dim GrChild As Graphic
            'Add child Graphics
' ##########################################################################
' ##########################################################################
        If ScrewView = "FrontSection" Then
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, True, True, False, False, False, False
                .Add X(7), Y(7), 0, True, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
                .Add X(1), Y(1), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Closed = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("BrushStyle") = "Solid"
            GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, False, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
        'Threading
            Set GrChild = Gr.Graphics.Add(gkGraphic)
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(8), Y(8), 0, True, True, False, False, False, False
                .Add X(9), Y(9), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
            End With
            GrChild.Cosmetic = True
            GrChild.Properties("PenColor") = PColor
        
        End If

End Sub


